<!DOCTYPE html>
<html>
	<head>
		<script src="/js/sink.js/audiolib.js"></script>
		<script src="/js/sink.js/pcmdata.js"></script>
		<script src="/js/sink.js/sink.js"></script>
		<script>
(function(){

var sampleRate, phase = 0, lfo = 0, lfo2 = 0, sink;

window.onload	= function () {
	sink = new Sink.sinks.wav();

	if (!sink.type === 'wav') return console.error('Not an instance of the WAV sink.');

	sink.on('audioprocess', function (buffer, channelCount) {
		var i, n;
		for (i=0; i<buffer.length; i+=channelCount) {
			phase = (phase + 440 / sampleRate / 2) % 1;
			for (n=0; n<channelCount; n++) {
				buffer[i+n] += Math.sin(phase * Math.PI * 2) * 0.5;
			}
		}
	});

	sink.on('audioprocess', function (buffer, channelCount) {
		var i, n;
		for (i=0; i<buffer.length; i+=channelCount) {
			lfo2 = (lfo2 + 0.1 / sampleRate / 2) % 1;
			lfo = (lfo + (Math.sin(lfo2 * Math.PI * 2) + 2) * 111 / sampleRate / 2) % 1;
			for (n=0; n<channelCount; n++) {
				buffer[i+n] *= Math.sin(lfo * Math.PI * 2);
			}
		}
	});

	sampleRate = Sink.singleton().sampleRate;

	sink.on('error', function(e){
		console.error(e);
	});
};

}());

		</script>
	</head>
	<body>
	</body>
</html>
